//
//  MotionCategory.m
//  CoreMotionDemo
//
//  Created by 曹敬贺 on 16/9/14.
//  Copyright © 2016年 北京无限点乐科技有限公司. All rights reserved.
//

#import "MotionCategory.h"


@implementation MotionCategory

- (void)testPedometerData
{
    if ([CMPedometer isStepCountingAvailable]) {
        NSLog(@"可以获得");
//        这里要设置成属性
        self.pedometer = [[CMPedometer alloc]init];
        [self.pedometer queryPedometerDataFromDate:[NSDate dateWithTimeIntervalSince1970:time(NULL)-3600*24*5] toDate:[NSDate date] withHandler:^(CMPedometerData *pedometerData, NSError *error) {
            int steps = [pedometerData.numberOfSteps intValue];
            NSLog(@"跑了%d步",steps);
        }];
    }else
    {
        NSLog(@"不可获得");
    }
}

- (void)testAltimeterData
{
    if ([CMAltimeter isRelativeAltitudeAvailable]) {
        [self.altimeter stopRelativeAltitudeUpdates];
        [self.altimeter startRelativeAltitudeUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAltitudeData *altitudeData, NSError *error) {
            if (!error) {
                float altitude = [altitudeData.relativeAltitude floatValue];
                float kPa = [altitudeData.pressure floatValue];
                NSLog(@"海拔:%f米  气压:%.2f(千帕)",altitude * 1000,kPa);
            }
        }];
    }else
    {
        NSLog(@"气压计不可用");
    }
}



@end
